From b944c20a97c774bd76f5bc5618171144093fa722 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 7 Aug 2008 02:10:38 +0000 Subject: [PATCH] Markus Spoetti adds lap splitting to Garmin Training Center. --- gpsbabel/defs.h | 2 ++ gpsbabel/garmin.c | 43 +++++++++++++++++++++++++++++++++++++++++++ gpsbabel/gtrnctr.c | 7 ++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 92e5e6dbe..6f8ad4536 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -335,6 +335,8 @@ typedef struct { unsigned int altitude:1; /+ altitude field is set +/ ... and others */ + unsigned int is_split:1; /* the waypoint represents a split */ + } wp_flags; diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index 1336ec18f..db800c072 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -352,6 +352,40 @@ waypt_read(void) } } +static int lap_read_nop_cb(int n, struct GPS_SWay** dp) +{ + return 0; +} + +// returns 1 if the waypoint's start_time can be found +// in the laps array, 0 otherwise +unsigned int checkWayPointIsAtSplit(waypoint *wpt, GPS_PLap *laps, int nlaps) +{ + int result = 0; + + if ((laps != NULL) && (nlaps > 0)) { + int i; + for (i=(nlaps-1); i >= 0; i--) { + GPS_PLap lap = laps[i]; + time_t delta = lap->start_time - wpt->creation_time; + if ((delta >= -1) && (delta <= 1)) { + result = 1; + break; + + // as an optimization this will stop going through + // the lap array when the negative delta gets too + // big. It assumes that laps is sorted by time in + // ascending order (which appears to be the case for + // Forerunners. Don't know about other devices. + } else if (delta < -1) { + break; + } + } + } + + return result; +} + static void track_read(void) @@ -364,6 +398,13 @@ track_read(void) int trk_seg_num = 1; char trk_seg_num_buf[10]; char *trk_name = ""; + GPS_PLap* laps = NULL; + int nlaps = 0; + + if (gps_lap_type != -1) { + nlaps = GPS_Command_Get_Lap(portname, &laps, &lap_read_nop_cb); + } + ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb); @@ -414,6 +455,8 @@ track_read(void) wpt->cadence = array[i]->cadence; wpt->shortname = xstrdup(array[i]->trk_ident); wpt->creation_time = array[i]->Time; + wpt->wpt_flags.is_split = checkWayPointIsAtSplit(wpt, laps, + nlaps); track_add_wpt(trk_head, wpt); } diff --git a/gpsbabel/gtrnctr.c b/gpsbabel/gtrnctr.c index 12446e91b..296f6bef2 100644 --- a/gpsbabel/gtrnctr.c +++ b/gpsbabel/gtrnctr.c @@ -120,7 +120,12 @@ gtc_waypt_pr(const waypoint *wpt) xml_write_time(ofd, wpt->creation_time, "Time"); gbfprintf(ofd, " \n"); #else - gtc_write_xml(1, "\n"); + if (wpt->wpt_flags.is_split != 0) { + gtc_write_xml(1, "\n"); + } else { + gtc_write_xml(1, "\n"); + } + if (wpt->creation_time) { char time_string[100]; xml_fill_in_time(time_string, wpt->creation_time, wpt->microseconds, -- 2.30.2